package com.base.api;

import com.base.core.utils.UploadUtil;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.model.ObjectMetadata;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;

import com.base.config.UploadConfig;
import com.base.core.model.ApiRes;
import com.base.core.constant.Enums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description: 文件上传
 * @Author: zjl
 */
@SuppressWarnings("ALL")
@Api(tags = "文件上传")
@RestController
@RequestMapping("/file")
public class UploadFileController extends BaseController {


    /**
     * 简单文件上传 file 简单文件上传上传(最大支持 5 GB, 适用于小文件上传, 建议 20 M 以下的文件使用) 5242880
     * 上传到腾讯COS
     * @param file
     * @return
     */
    @ApiOperation(value = "文件上传")
    @PostMapping(value = "/uploadToCOS")
    public ApiRes upload(MultipartFile file) {
        if (file.isEmpty()) {
            return ApiRes.failed(Enums.ResponseStatus.MISS_DATA);
        }
        return ApiRes.success(UploadUtil.uploadMultipartFileToTencentCOS(file));

    }
}
